/**
 * Mocking client-server processing
 */
const _goods = [
  {"id": 1, "title": "新鲜水果", "price": "12.5", "surplus": 15},
  {"id": 2, "title": "新鲜水果", "price": "22.5", "surplus": 25},
  {"id": 3, "title": "新鲜水果", "price": "33.5", "surplus": 35}
]

export default {
  getProducts (cb) {
    setTimeout(() => cb(_products), 100)
  },

  buyProducts (products, cb, errorCb) {
    setTimeout(() => {
      // simulate random checkout failure.
      (Math.random() > 0.5 || navigator.userAgent.indexOf('PhantomJS') > -1)
        ? cb()
        : errorCb()
    }, 100)
  }
}
